
package com.dewod.producesales.adapter;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.dewod.producesales.R;
import com.dewod.producesales.model.view.CabinetSn;
import com.google.android.material.checkbox.MaterialCheckBox;

import java.util.List;

public class CabinetSnAdapter extends RecyclerView.Adapter<CabinetSnAdapter.ViewHolder> {

    private List<CabinetSn> snList;

    public CabinetSnAdapter(List<CabinetSn> cabinetSnList) {
        this.snList = cabinetSnList;
    }

    public void updateData(List<CabinetSn> snList) {
        this.snList = snList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_cabinet_sn, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CabinetSn cabinetSn = snList.get(position);
        holder.checkBox.setText(cabinetSn.getSn());
        holder.checkBox.setChecked(cabinetSn.getChecked());
    }

    @Override
    public int getItemCount() {
        return snList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        MaterialCheckBox checkBox;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            checkBox = itemView.findViewById(R.id.material_checkbox);
        }
    }
}